from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

"""
TimedJSONWebSignatureSerializer
有过期时间 
secret_key 签名 加签 加盐
"""


class SecretOauth(object):
    def __init__(self):
        self.serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)

    # 加密
    def dumps(self, data):
        result = self.serializer.dumps(data)

        # result -- bytes
        return result.decode()

    # 解密
    def loads(self, data):
        return self.serializer.loads(data)

#
# s = Serializer(secret_key=settings.SECRET_KEY)
#
# data_dict = {
#     'name': 'laowang'
# }
#
# # 加密 --bytes-->decode()
# result = s.dumps(data_dict)
#
# print(result.decode())
#
# # 解密
# result = s.loads(result.decode())
# print(result)
